/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package gui.benhan;

import control.benhan.BAMainPanel_Ctrl;
import gui.event.benhan.BAMainPanel_evt;
import java.sql.DatabaseMetaData;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
/**
 *
 * @author Admin
 */
public class BAMainPanel extends javax.swing.JPanel {

    /**
     * Creates new form BAMainPanel
     */
    private List<JButton> listButtons;
//    private ButtonGroup gLietKe;
    
    public BAMainPanel() {
        initComponents();
        this.setName("Quản Lý Bệnh Án");
        
        //thêm 2 button vào listButton, để quản lý event khi chọn 1 row ở bảng bệnh án
        listButtons = new ArrayList<JButton>();
        listButtons.add(btnChiTiet);
        listButtons.add(btnSua);
        BAMainPanel_Ctrl.LoadAllBenhAn(btlHSBA);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlDieuKienLietKe = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtMaBenhAn = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        spinSoLuongPhieuDieuTri = new javax.swing.JSpinner();
        jLabel3 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtTenBenh = new javax.swing.JTextField();
        btnLietKe = new javax.swing.JButton();
        jDateChooserDayKhám = new com.toedter.calendar.JDateChooser();
        btnThem = new javax.swing.JButton();
        btnSua = new javax.swing.JButton();
        btnIn = new javax.swing.JButton();
        btnChiTiet = new javax.swing.JButton();
        btnClose = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        btlHSBA = new javax.swing.JTable();
        btnDelete = new javax.swing.JButton();

        pnlDieuKienLietKe.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Điều kiện liệt kê", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 204)));
        pnlDieuKienLietKe.setInheritsPopupMenu(true);

        jLabel1.setText("Mã bệnh án");

        txtMaBenhAn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtMaBenhAnActionPerformed(evt);
            }
        });

        jLabel2.setText("Số lượng phiếu điều trị");

        jLabel3.setText("Ngày khám");

        jLabel6.setText("Tên bệnh");

        btnLietKe.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/images/ultility/Filter-Standard-16.png"))); // NOI18N
        btnLietKe.setText("Liệt kê");
        btnLietKe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLietKeActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlDieuKienLietKeLayout = new javax.swing.GroupLayout(pnlDieuKienLietKe);
        pnlDieuKienLietKe.setLayout(pnlDieuKienLietKeLayout);
        pnlDieuKienLietKeLayout.setHorizontalGroup(
            pnlDieuKienLietKeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDieuKienLietKeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDieuKienLietKeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(pnlDieuKienLietKeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(spinSoLuongPhieuDieuTri, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtMaBenhAn, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(157, 157, 157)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jDateChooserDayKhám, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 281, Short.MAX_VALUE)
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(txtTenBenh, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(152, 152, 152))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlDieuKienLietKeLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnLietKe, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        pnlDieuKienLietKeLayout.setVerticalGroup(
            pnlDieuKienLietKeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDieuKienLietKeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDieuKienLietKeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlDieuKienLietKeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlDieuKienLietKeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel6)
                            .addComponent(txtTenBenh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pnlDieuKienLietKeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtMaBenhAn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pnlDieuKienLietKeLayout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jDateChooserDayKhám, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(pnlDieuKienLietKeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlDieuKienLietKeLayout.createSequentialGroup()
                        .addGroup(pnlDieuKienLietKeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(spinSoLuongPhieuDieuTri, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(29, 29, 29))
                    .addGroup(pnlDieuKienLietKeLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
                        .addComponent(btnLietKe)
                        .addContainerGap())))
        );

        btnThem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/images/benhan/Book-Close-16 addnew.png"))); // NOI18N
        btnThem.setText("Tạo");
        btnThem.setToolTipText("Tạo Bệnh Án Mới");
        btnThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThemActionPerformed(evt);
            }
        });

        btnSua.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/images/benhan/Book-Close-16 edit.png"))); // NOI18N
        btnSua.setText("Sửa...");
        btnSua.setToolTipText("Sửa Hồ Sơ Bệnh Án");
        btnSua.setEnabled(false);
        btnSua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSuaActionPerformed(evt);
            }
        });

        btnIn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/images/ultility/Printer-16.png"))); // NOI18N
        btnIn.setText("In...");
        btnIn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInActionPerformed(evt);
            }
        });

        btnChiTiet.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/images/ultility/View-Details-16.png"))); // NOI18N
        btnChiTiet.setText("Chi Tiết");
        btnChiTiet.setEnabled(false);
        btnChiTiet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChiTietActionPerformed(evt);
            }
        });

        btnClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/images/ultility/Close-16.png"))); // NOI18N
        btnClose.setText("Đóng");
        btnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCloseActionPerformed(evt);
            }
        });

        btlHSBA.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"BA001", null, null, null, "Dại", "10/05/2014", "20/05/2014", "Còn Bệnh", "Tiến Triển Tốt"},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Mã hồ sơ bệnh án", "Mã vật nuôi", "Tên vật nuôi", "Mã bệnh", "Tên bệnh", "Ngày bắt đầu", "Ngày kết thúc", "Trạng thái", "Ghi chú"
            }
        ));
        btlHSBA.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                btlHSBAFocusGained(evt);
            }
        });
        jScrollPane1.setViewportView(btlHSBA);

        btnDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/images/benhan/Book-Close-16 delete.png"))); // NOI18N
        btnDelete.setText("Xoá...");
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlDieuKienLietKe, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnThem, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSua, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnIn, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnChiTiet)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnClose, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(9, 9, 9))
                    .addComponent(jScrollPane1))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlDieuKienLietKe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnThem)
                        .addComponent(btnSua)
                        .addComponent(btnIn)
                        .addComponent(btnChiTiet))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnDelete)
                        .addComponent(btnClose)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE)
                .addContainerGap())
        );

        jScrollPane1.getAccessibleContext().setAccessibleParent(jScrollPane1);
    }// </editor-fold>//GEN-END:initComponents

    private void btnLietKeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLietKeActionPerformed
        BAMainPanel_evt.btnLietKeActionPerformed();
        BAMainPanel_Ctrl.lietKeTheoTenBA(txtTenBenh, btlHSBA);
        BAMainPanel_Ctrl.lietKeTheoMaBA(txtMaBenhAn, btlHSBA);
        btlHSBA.resetKeyboardActions();
    }//GEN-LAST:event_btnLietKeActionPerformed

    private void btnThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThemActionPerformed
        BAMainPanel_evt.btnThemActionPerformed(this.btlHSBA);
    }//GEN-LAST:event_btnThemActionPerformed

    private void btnChiTietActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChiTietActionPerformed
       BAMainPanel_evt.btnChiTietActionPerformed(btlHSBA);
    }//GEN-LAST:event_btnChiTietActionPerformed

    private void btnInActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInActionPerformed
        BAMainPanel_evt.btnInActionPerformed(btlHSBA);
    }//GEN-LAST:event_btnInActionPerformed

    private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
        BAMainPanel_evt.btnCloseActionPerformed(this, (JTabbedPane) this.getParent());
    }//GEN-LAST:event_btnCloseActionPerformed

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
        BAMainPanel_evt.btnDeleteActionPerformed(btlHSBA);
    }//GEN-LAST:event_btnDeleteActionPerformed

    private void btlHSBAFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_btlHSBAFocusGained
        BAMainPanel_evt.btlHSBAFocusGained(this.listButtons, this.btlHSBA);
    }//GEN-LAST:event_btlHSBAFocusGained

    private void btnSuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSuaActionPerformed
        BAMainPanel_evt.btnSuaActionPerformed(btlHSBA);
    }//GEN-LAST:event_btnSuaActionPerformed

    private void txtMaBenhAnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtMaBenhAnActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtMaBenhAnActionPerformed
	
	
    public JTable getBtlHSBA() {
        return btlHSBA;
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable btlHSBA;
    private javax.swing.JButton btnChiTiet;
    private javax.swing.JButton btnClose;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnIn;
    private javax.swing.JButton btnLietKe;
    private javax.swing.JButton btnSua;
    private javax.swing.JButton btnThem;
    private com.toedter.calendar.JDateChooser jDateChooserDayKhám;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel pnlDieuKienLietKe;
    private javax.swing.JSpinner spinSoLuongPhieuDieuTri;
    private javax.swing.JTextField txtMaBenhAn;
    private javax.swing.JTextField txtTenBenh;
    // End of variables declaration//GEN-END:variables
}
